package com.example.mybatisflexdemo.convertor;

import com.example.mybatisflexdemo.dto.UserAddDTO;
import com.example.mybatisflexdemo.dto.UserDTO;
import com.example.mybatisflexdemo.entity.User;
import com.example.mybatisflexdemo.util.FileUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.springframework.web.multipart.MultipartFile;
import com.example.mybatisflexdemo.vo.UserAddVO;
import com.example.mybatisflexdemo.vo.UserVO;

import java.util.List;

@Mapper(componentModel = "spring", uses = FileUtils.class)
public interface UserConvertor {

    // 获取实例（如果不用Spring注入，可以用这个）
    // UserConvertor INSTANCE = Mappers.getMapper(UserConvertor.class);

    UserVO convertDtoToVo(UserDTO userDTO);

    List<UserVO> convertDtoToVoList(List<UserDTO> userDTOList);

    UserDTO convertDoToDto(User user);

    List<UserDTO> convertDoToDtoList(List<User> users);

    UserAddDTO convertAddVoToAddDto(UserAddVO user);

    @Mapping(target = "avatar", source = "avatarFile")
    @Mapping(target = "name", source = "userAddDTO.name")
    User convertAddDtoToDo(UserAddDTO userAddDTO, MultipartFile avatarFile);
}
